<?php
App::import('Model','JadwalKerja');

class JadwalKerjaBL extends JadwalKerja {
   
   public function createJadwalKerja(array $data = array(), $dataSession = array()) {
         $ret = null;
         
         $dataJadwal = array();
         
         // --- create cakephp array structure for save() method
         $dataJadwal['JadwalKerja'] = array(
             'name' => $data['JadwalKerja']['name'],
             'perputaran' => $data['JadwalKerja']['perputaran'],
             'awal_masa_berlaku' => $data['JadwalKerja']['tanggal_mulai'],
             'akhir_masa_berlaku' => $data['JadwalKerja']['tanggal_berakhir']
         );
         
         if (count($dataSession) >= 1) {
            
            // --- read session JadwalKerja
            foreach ($dataSession['jadwal_hari'] as $v) {
               $dataJadwal['JadwalKerja']['hari_'.$v['hari']] = $v['jam_kerja_id'];
            }
            
            $this->create($dataJadwal);
            if ($this->save($dataJadwal)) {
               $ret = true;
            } else {
               $ret = $this->invalidFields();
            }
         }
         
         return $ret;
         
      }
      
      public function jadwalKerjaFind($type = 'all', $options = array()) {
         return $this->find($type,$options);
      }


      public function callOtherModelObject() {
         $otherMethod = ClassRegistry::init('JamKerja');
         ClassRegistry::flush();
         
         return $otherMethod->find('list');
      }
}

